package com.nlscan.techhub.catalog.feature.system.deviceinfo.view

import android.os.Build
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.nlscan.ncomgateway.databinding.SysActivitySystemPropertyBinding
import com.nlscan.techhub.catalog.feature.system.deviceinfo.adapter.SystemPropertyAdapter
import com.nlscan.techhub.catalog.feature.system.deviceinfo.model.SystemPropertyItem
import com.nlscan.qdkit.ui.publico.art.mvvm.BaseMvvmActivity
import androidx.lifecycle.ViewModelProvider
import com.quvii.qvmvvm.core.base.KtxBaseViewModel
import com.nlscan.techhub.catalog.feature.system.deviceinfo.viewmodel.SystemPropertyViewModel

class SystemPropertyActivity : BaseMvvmActivity<SysActivitySystemPropertyBinding>() {

    private lateinit var viewModel: SystemPropertyViewModel
    private lateinit var adapter: SystemPropertyAdapter

    override fun getViewBinding(): SysActivitySystemPropertyBinding {
        return SysActivitySystemPropertyBinding.inflate(layoutInflater)
    }

    override fun startObserve(): KtxBaseViewModel {
        viewModel = ViewModelProvider(this)[SystemPropertyViewModel::class.java]
        return viewModel
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitleBar("系统属性")
        adapter = SystemPropertyAdapter(mutableListOf())

        loadSystemProperties()
        initRecyclerView()
    }

    private fun initRecyclerView() {
        binding.recyclerView.apply {
            layoutManager = LinearLayoutManager(this@SystemPropertyActivity)

        }
        binding.recyclerView.adapter = adapter
    }

    override fun initData() {
    }

    private fun loadSystemProperties() {
        val properties = mutableListOf<SystemPropertyItem>().apply {
            add(SystemPropertyItem("OS Version", Build.VERSION.RELEASE))
            add(SystemPropertyItem("API Level", Build.VERSION.SDK_INT.toString()))
            add(SystemPropertyItem("Device", Build.DEVICE))
            add(SystemPropertyItem("Model", Build.MODEL))
            add(SystemPropertyItem("Product", Build.PRODUCT))
            add(SystemPropertyItem("Brand", Build.BRAND))
            add(SystemPropertyItem("Manufacturer", Build.MANUFACTURER))
            add(SystemPropertyItem("Board", Build.BOARD))
            add(SystemPropertyItem("Hardware", Build.HARDWARE))
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                add(SystemPropertyItem("Security Patch", Build.VERSION.SECURITY_PATCH))
            }
        }

        adapter.setList(properties)
    }
}